Graphic design standards, especially for color, are an official Good Thing. Branding, visual cueing, consistency. Map colors are hard, especially when dealing with continuous data.
The U.S. Bureau of Economic Analysis publishes quarterly statistics on gross domestic product by state.1. For the second quarter 2018, it provided the following.
| NAME | GDP |
|---|---|
| Alabama | 221,026,000 |
| Alaska | 53,944,000 |
| Arizona | 344,636,000 |
| Arkansas | 127,951,000 |
| California | 2,935,332,000 |
| Colorado | 363,845,000 |
| Connecticut | 272,745,000 |
| Delaware | 74,717,000 |
| Florida | 1,029,154,000 |
| Georgia | 587,325,000 |
| Hawaii | 91,048,000 |
| Idaho | 76,187,000 |
| Illinois | 859,067,000 |
| Indiana | 369,209,000 |
| Iowa | 189,299,000 |
| Kansas | 164,018,000 |
| Kentucky | 209,562,000 |
| Louisiana | 249,726,000 |
| Maine | 64,203,000 |
| Maryland | 414,373,000 |
| Massachusetts | 569,290,000 |
| Michigan | 532,039,000 |
| Minnesota | 362,904,000 |
| Mississippi | 113,334,000 |
| Missouri | 316,735,000 |
| Montana | 49,514,000 |
| Nebraska | 123,363,000 |
| Nevada | 167,708,000 |
| New Hampshire | 85,548,000 |
| New Jersey | 626,824,000 |
| New Mexico | 98,390,000 |
| New York | 1,675,685,000 |
| North Carolina | 565,300,000 |
| North Dakota | 55,180,000 |
| Ohio | 672,055,000 |
| Oklahoma | 199,572,000 |
| Oregon | 238,687,000 |
| Pennsylvania | 788,842,000 |
| Rhode Island | 61,168,000 |
| South Carolina | 230,213,000 |
| South Dakota | 51,721,000 |
| Tennessee | 365,129,000 |
| Texas | 1,755,634,000 |
| Utah | 175,601,000 |
| Vermont | 33,522,000 |
| Virginia | 532,896,000 |
| Washington | 559,011,000 |
| West Virginia | 77,748,000 |
| Wisconsin | 335,560,000 |
| Wyoming | 40,384,000 |
The two obvious things from the chart are that the numbers differ and that in general the larger states in population are also the larger states in GDP. Whenever making maps of continuous data, they will almost always turn out like this, unless there are marked regional differences and you take the default option.
Here is the GDP data, also with the default option.
If we are looking for more interesting differences among states, we should put them on a common footing, so that population size alone doesn’t dominate the effects. For disease, as an example, cases per hundred thousand is commonly used. Here’s what the GDP data looks like on that basis.
The default continuous blue scale, even with transformed data, still requires squinting to distinguish different values.
We can tinker with that by applying an alpha (density) filter.
The signature for scale_alpha_continuous is
scale_alpha_continuous(…, range = c(0.1, 1))
The range can be narrowed
scale_alpha_continuous(range = c(0.1, 0.75))
or even further lightened
scale_alpha_continuous(range = c(0.1, 0.50))
Five bright (some might say garish) scales are available.
scale_fill_viridis_c(option="magma")
scale_fill_viridis_c(option="inferno")
scale_fill_viridis_c(option="plasma")
scale_fill_viridis_c(option="viridis")
scale_fill_viridis_c(option="viridis")
Fortunately, the palette can be muted with an alpha density filter
scale_fill_viridis_c(alpha = 0.50, option="cividis")
scale_fill_gradient can also over-ride default colorsThe signature of scale_fill_gradient is
scale_fill_gradient(..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "fill")
in the blue range. You can adjust that with the arguments to low and high. The following example uses #FBF7F6 and #A97263.
How did I come up with those particular values?
library(munsell)
show_col(seq_gradient_pal("white", mnsl("10R 4/6"))(x))(seq(0, 1, length.out = 25)))
This approach, and other do-it-yourself color palette selection approaches can become a time sink.See R color cheatsheet A better approach is to have a selection of pre-made color cards, and try them out until one of them highlights the differences you are trying to show.
This set of palettes plays well with ggplot and should answer most needs.
RColorBrewer
The three sections are for sequential (i.e., continuous), divergent (a neutral color in the center progressing toward more intense colors in both direction) or qualitative, for discrete data but coercible into continuous data.
Through ggplot’s scale_colour_distiller function, any of these can be smoothly interpolated into a six-interval scale.
All of the scales can be flipped, working from left-to-right on the palette or from right-to-left. Direction is indicated by direction = -1 or direction = 1.
Color abbreviations:
There are also:
The signature for scale_colour_distiller is
scale_fill_distiller(type = “seq”, palette = “YlOrRd”, direction = -1, labels = comma, guide = “colourbar”, aesthetics = “fill”)